/*
Navicat SQL Server Data Transfer

Source Server         : Balder@UCN
Source Server Version : 105000
Source Host           : Balder.ucn.dk:1433
Source Database       : dmaa0912_E7
Source Schema         : dbo

Target Server Type    : SQL Server
Target Server Version : 105000
File Encoding         : 65001

Date: 2013-10-17 15:34:31
*/


-- ----------------------------
-- Table structure for Hall
-- ----------------------------
DROP TABLE [dbo].[Hall]
GO
CREATE TABLE [dbo].[Hall] (
[Id] int NOT NULL IDENTITY(1,1) ,
[Number] int NOT NULL 
)


GO

-- ----------------------------
-- Table structure for Movie
-- ----------------------------
DROP TABLE [dbo].[Movie]
GO
CREATE TABLE [dbo].[Movie] (
[Id] int NOT NULL IDENTITY(1,1) ,
[Name] varchar(60) NOT NULL ,
[RunTime] time(7) NULL ,
[Genre] varchar(20) NULL ,
[ThirdDimensional] bit NULL ,
[Language] varchar(20) NULL ,
[Subtitles] varchar(20) NULL ,
[Description] varchar(255) NOT NULL 
)


GO

-- ----------------------------
-- Table structure for Reservation
-- ----------------------------
DROP TABLE [dbo].[Reservation]
GO
CREATE TABLE [dbo].[Reservation] (
[Id] int NOT NULL IDENTITY(1,1) ,
[IsPaid] bit NOT NULL ,
[ShowId] int NOT NULL ,
[UserId] int NOT NULL 
)


GO

-- ----------------------------
-- Table structure for Row
-- ----------------------------
DROP TABLE [dbo].[Row]
GO
CREATE TABLE [dbo].[Row] (
[Id] int NOT NULL IDENTITY(1,1) ,
[Number] int NOT NULL ,
[HallId] int NOT NULL 
)


GO

-- ----------------------------
-- Table structure for Seat
-- ----------------------------
DROP TABLE [dbo].[Seat]
GO
CREATE TABLE [dbo].[Seat] (
[Id] int NOT NULL IDENTITY(1,1) ,
[Number] int NOT NULL ,
[Type] varchar(20) NOT NULL ,
[RowID] int NOT NULL 
)


GO

-- ----------------------------
-- Table structure for Show
-- ----------------------------
DROP TABLE [dbo].[Show]
GO
CREATE TABLE [dbo].[Show] (
[Id] int NOT NULL IDENTITY(1,1) ,
[Name] varchar(55) NOT NULL ,
[Length] time(7) NOT NULL ,
[Time] datetime NOT NULL ,
[MovieId] int NOT NULL ,
[HallId] int NOT NULL ,
[TicketId] int NOT NULL 
)


GO

-- ----------------------------
-- Table structure for Ticket
-- ----------------------------
DROP TABLE [dbo].[Ticket]
GO
CREATE TABLE [dbo].[Ticket] (
[Id] int NOT NULL IDENTITY(1,1) ,
[ReservationType] varchar(20) NOT NULL ,
[ReservationId] int NOT NULL ,
[SeatId] int NOT NULL ,
[ShowId] int NOT NULL ,
[Number] varchar(20) NULL 
)


GO

-- ----------------------------
-- Table structure for User
-- ----------------------------
DROP TABLE [dbo].[User]
GO
CREATE TABLE [dbo].[User] (
[Id] int NOT NULL IDENTITY(1,1) ,
[Email] varchar(100) NOT NULL ,
[LastName] varchar(55) NOT NULL ,
[FirstName] varchar(55) NOT NULL ,
[Address] varchar(80) NULL ,
[City] varchar(40) NULL ,
[ZipCode] int NULL ,
[PhoneNumber] int NOT NULL ,
[PassCode] varchar(60) NOT NULL 
)


GO

-- ----------------------------
-- Indexes structure for table Hall
-- ----------------------------

-- ----------------------------
-- Primary Key structure for table Hall
-- ----------------------------
ALTER TABLE [dbo].[Hall] ADD PRIMARY KEY ([Id])
GO

-- ----------------------------
-- Indexes structure for table Movie
-- ----------------------------

-- ----------------------------
-- Primary Key structure for table Movie
-- ----------------------------
ALTER TABLE [dbo].[Movie] ADD PRIMARY KEY ([Id])
GO

-- ----------------------------
-- Indexes structure for table Reservation
-- ----------------------------

-- ----------------------------
-- Primary Key structure for table Reservation
-- ----------------------------
ALTER TABLE [dbo].[Reservation] ADD PRIMARY KEY ([Id])
GO

-- ----------------------------
-- Indexes structure for table Row
-- ----------------------------

-- ----------------------------
-- Primary Key structure for table Row
-- ----------------------------
ALTER TABLE [dbo].[Row] ADD PRIMARY KEY ([Id])
GO

-- ----------------------------
-- Indexes structure for table Seat
-- ----------------------------

-- ----------------------------
-- Primary Key structure for table Seat
-- ----------------------------
ALTER TABLE [dbo].[Seat] ADD PRIMARY KEY ([Id])
GO

-- ----------------------------
-- Indexes structure for table Show
-- ----------------------------

-- ----------------------------
-- Primary Key structure for table Show
-- ----------------------------
ALTER TABLE [dbo].[Show] ADD PRIMARY KEY ([Id])
GO

-- ----------------------------
-- Indexes structure for table Ticket
-- ----------------------------

-- ----------------------------
-- Primary Key structure for table Ticket
-- ----------------------------
ALTER TABLE [dbo].[Ticket] ADD PRIMARY KEY ([Id])
GO

-- ----------------------------
-- Indexes structure for table User
-- ----------------------------

-- ----------------------------
-- Primary Key structure for table User
-- ----------------------------
ALTER TABLE [dbo].[User] ADD PRIMARY KEY ([Id])
GO

-- ----------------------------
-- Foreign Key structure for table [dbo].[Reservation]
-- ----------------------------
ALTER TABLE [dbo].[Reservation] ADD FOREIGN KEY ([ShowId]) REFERENCES [dbo].[Show] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION
GO
ALTER TABLE [dbo].[Reservation] ADD FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION
GO

-- ----------------------------
-- Foreign Key structure for table [dbo].[Row]
-- ----------------------------
ALTER TABLE [dbo].[Row] ADD FOREIGN KEY ([HallId]) REFERENCES [dbo].[Hall] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION
GO

-- ----------------------------
-- Foreign Key structure for table [dbo].[Seat]
-- ----------------------------
ALTER TABLE [dbo].[Seat] ADD FOREIGN KEY ([RowID]) REFERENCES [dbo].[Row] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION
GO

-- ----------------------------
-- Foreign Key structure for table [dbo].[Show]
-- ----------------------------
ALTER TABLE [dbo].[Show] ADD FOREIGN KEY ([HallId]) REFERENCES [dbo].[Hall] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION
GO
ALTER TABLE [dbo].[Show] ADD FOREIGN KEY ([MovieId]) REFERENCES [dbo].[Movie] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION
GO
ALTER TABLE [dbo].[Show] ADD FOREIGN KEY ([TicketId]) REFERENCES [dbo].[Ticket] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION
GO

-- ----------------------------
-- Foreign Key structure for table [dbo].[Ticket]
-- ----------------------------
ALTER TABLE [dbo].[Ticket] ADD FOREIGN KEY ([ReservationId]) REFERENCES [dbo].[Reservation] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION
GO
ALTER TABLE [dbo].[Ticket] ADD FOREIGN KEY ([SeatId]) REFERENCES [dbo].[Seat] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION
GO
ALTER TABLE [dbo].[Ticket] ADD FOREIGN KEY ([ShowId]) REFERENCES [dbo].[Show] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION
GO
